package com.gwu.manger.controller;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.gwu.manger.dto.ResponseList;
import com.gwu.manger.dto.ResponseModel;
import com.gwu.manger.dto.ResponseResult;
import com.gwu.manger.po.User;
import com.gwu.manger.service.RedisService;
import com.gwu.manger.service.UserService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

 

/**
 * @author gwu
 * @version v1.0
 * @since 2020/11/18 09:30
 */
@RestController
@RequestMapping("user")
@Api(tags = "用户管理")
public class UserManagerController {
	@Autowired
	private UserService userService;
	@Autowired
	RedisService redisService;
  @PostMapping
  @ApiOperation(value = "listUser", notes = "返回列表数据")
  @RequestMapping(value = "/listUser", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
  public ResponseResult listUser(@RequestBody User user) {
    System.out.println(user.toString());
    List<User> list=new ArrayList<User>();
    for(int i=0;i<5;i++) {
    	User  u=new User();
    	u.setUid(i);
    	u.setAccount("gwu"+i);
    	list.add(u);
    }
    ResponseList<User>  re=new ResponseList<User>();
    re.setList(list);
	return ResponseResult.success(re);
  }
  
  
  @PostMapping
  @ApiOperation(value = "modelUser", notes = "返回对象数据")
  @RequestMapping(value = "/modelUser", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
  public ResponseResult modelUser(@RequestBody User user) {
    System.out.println(user.toString());
    List<User> list=new ArrayList<User>();
    for(int i=0;i<5;i++) {
    	User  u=new User();
    	u.setUid(i);
    	u.setAccount("gwu"+i);
    	list.add(u);
    }
    ResponseModel<User>  re=new ResponseModel<User>();
    re.setModel(user);
	return ResponseResult.success(re);
  }
  
  
  
  @PostMapping
  @ApiOperation(value = "addUser", notes = "添加用户")
  @RequestMapping(value = "/addUser", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
  
  public ResponseResult addUser(@RequestBody User user,@RequestHeader String token) {
    System.out.println(user.toString());
	return ResponseResult.success();
  }
  
  
  
  @PostMapping
  @ApiOperation(value = "testRdis", notes = "测试redis")
  @RequestMapping(value = "/testRdis", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
  public ResponseResult testRdis(@RequestBody User user) {
    System.out.println(user.toString());
    
    List<User> list=new ArrayList<User>();
    for(int i=0;i<5;i++) {
    	User  u=new User();
    	u.setUid(i);
    	u.setAccount("gwu"+i);
    	list.add(u);
    }
    
    ResponseList<User>  re=new ResponseList<User>();
    re.setList(list);
    
    redisService.setKey("list", re);
	return ResponseResult.success(redisService.getKey("list"));
  }
 
@PostMapping
@ApiOperation(value = "listMybatisPlusList", notes = "通过MybatisPlusList")
@RequestMapping(value = "/listMybatisPlusList", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
public ResponseResult listMybatisPlusList(@RequestBody User user) {
  List<User> list=userService.getAllList();
  ResponseList<User>  re=new ResponseList<User>();
  re.setList(list);
	return ResponseResult.success(re);
}
 

 
}